package com.作业.Day22;


import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * 利用的是dbutils
 */
public class Homework2 {
    public static void main(String[] args) throws SQLException {
        QueryRunner queryRunner = new QueryRunner();
        MyJDBC myJDBC = new MyJDBC();

    }

    private static void select2(QueryRunner queryRunner, MyJDBC myJDBC) throws SQLException {
        String sql = "select * from bookdb where id = ?";
        Object[] objects = {1};
        List<Book> query = queryRunner.query(myJDBC.isConnect(),sql,new BeanListHandler<Book>(Book.class) , objects);
        System.out.println( query);
    }

    private static void select1(QueryRunner queryRunner, MyJDBC myJDBC) throws SQLException {
        //必须提供无参构造器
        List<Book> query = queryRunner.query(myJDBC.isConnect(), "select * from bookdb", new BeanListHandler<Book>(Book.class));
        System.out.println( query);
    }

    private static void update(QueryRunner queryRunner, MyJDBC myJDBC) throws SQLException {
        String sql = "insert into bookdb values(?,?,?,?,?,?)";
        Object[] objects = {1, "java", 10.0, "123456", "java", "java"};
        int update = queryRunner.update(myJDBC.isConnect(), sql, objects);
        System.out.println( update);
    }
}
